package com.mybatis.number.dao;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisConnectionFactory {

  private static SqlSessionFactory sqlSessionFactory;

  static {
    try {
      String resource = "com/mybatis/number/xml/Configuration.xml";
      Reader reader = Resources.getResourceAsReader(resource);

      if (sqlSessionFactory == null) {
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
      }
    } catch (Exception ex) {
      System.out.println(ex);
    }
  }

  public static SqlSessionFactory getSqlSessionFactory() {
    return sqlSessionFactory;
  }
}